(function(e){var i={};BX.namespace("BX.Disk");if(BX.Disk.UFMobile)return;BX.Disk.UFMobile=function(){var i=function(i){this.dialogName="DiskFileDialog";this.params=i;this.CID=i["UID"];this.controlName=i["controlName"];this.container=BX("diskuf-placeholder-"+i["UID"]);if(BX("diskuf-eventnode-"+i["UID"])){BX.bind(BX("diskuf-eventnode-"+i["UID"]),"click",BX.proxy(this.click,this))}this.handleAppFile=BX.delegate(this.handleAppFile,this);this.showDiskDialog=BX.delegate(this.showDiskDialog,this);this.handleDiskFile=BX.delegate(this.handleDiskFile,this);this.urls["upload"]=e.location.protocol+"//"+e.location.host+this.urls["upload"];this.urls["folder"]=e.location.protocol+"//"+e.location.host+BX.message("SITE_DIR")+this.urls["folder"];this.urls["getAttach"]=BX.message("SITE_DIR")+this.urls["getAttach"];this.urls["getFile"]=BX.message("SITE_DIR")+this.urls["getFile"];this.agent=BX.Uploader.getInstance({id:this.CID,streams:1,allowUpload:"A",uploadFormData:"N",uploadMethod:"immediate",uploadFileUrl:this.urls["upload"],showImage:true,sortItems:false,input:null,dropZone:null,placeHolder:this.container,queueFields:{thumb:{tagName:"DIV",className:"mobile-grid-field-file-item mobile-grid-field-file-file"}},fields:{thumb:{tagName:"",template:BX.message("DISK_NODE")},preview:{params:{width:212,height:119}}}});this.init(i["values"]);return this};i.prototype={urls:{upload:"/bitrix/tools/disk/uf.php?action=uploadFile&ncc=1",folder:"mobile/?mobile_action=disk_folder_list&type=user&path=%2F&entityId="+BX.message("USER_ID"),getAttach:"mobile/ajax.php?mobile_action=disk_uf_view&action=download&ncc=1&attachedId=#id#&filename=#name#",getFile:"mobile/ajax.php?mobile_action=disk_download_file&action=downloadFile&fileId=#id#&filename=#name#"},click:function(e){BX.PreventDefault(e);this.show();return false},show:function(){var i=[{title:BX.message("MPF_PHOTO_CAMERA"),callback:BX.delegate(function(){e.app.takePhoto({quality:80,source:1,correctOrientation:true,targetWidth:1024,targetHeight:1024,destinationType:e.Camera.DestinationType.DATA_URL,callback:this.handleAppFile})},this)},{title:BX.message("MPF_PHOTO_GALLERY"),callback:BX.delegate(function(){e.app.takePhoto({quality:80,targetWidth:1024,targetHeight:1024,destinationType:e.Camera.DestinationType.DATA_URL,callback:this.handleAppFile})},this)}];if(false&&e.platform=="android"){i.push({title:BX.message("MPF_PHOTO_DISK"),callback:this.showDiskDialog})}new e.BXMobileApp.UI.ActionSheet({buttons:i},"textPanelSheet").show()},handleAppFile:function(e){var i=BX.UploaderUtils.dataURLToBlob("data:image/jpg;base64,"+e);i.name="mobile_"+BX.date.format("Ymd_His")+".jpg";this.agent&&this.agent.onChange([i])},init:function(e){this._onFileIsCreated=BX.delegate(this.onFileIsCreated,this);this._onFileIsBound=BX.delegate(this.onFileIsBound,this);this._onFileIsAppended=BX.delegate(this.onFileIsAppended,this);this._onUploadStart=BX.delegate(this.onUploadStart,this);this._onUploadProgress=BX.delegate(this.onUploadProgress,this);this._onUploadDone=BX.delegate(this.onUploadDone,this);this._onUploadError=BX.delegate(this.onUploadError,this);BX.addCustomEvent(this.agent,"onFileIsCreated",this._onFileIsCreated);if(e&&e.length>0){var i=[],t=[],l;for(var a=0;a<e.length;a++){l=BX.findChild(e[a],{className:"mobile-grid-field-file-name"},true);if(BX(l)){i.push({name:l.innerHTML,id:e[a].getAttribute("id").replace("diskuf-","")});t.push(e[a])}}this.agent.onAttach(i,t)}},onFileIsCreated:function(e,i){if(i["file"]&&i["file"]["size"])i.size=BX.UploaderUtils.getFormattedSize(i.file.size,2);BX.addCustomEvent(i,"onFileIsBound",this._onFileIsBound);BX.addCustomEvent(i,"onFileIsAppended",this._onFileIsAppended);BX.addCustomEvent(i,"onUploadStart",this._onUploadStart);BX.addCustomEvent(i,"onUploadProgress",this._onUploadProgress);BX.addCustomEvent(i,"onUploadDone",this._onUploadDone);BX.addCustomEvent(i,"onUploadError",this._onUploadError)},onFileIsBound:function(e,i){this.bindFile(i)},onFileIsAppended:function(e,i){this.bindFile(i)},onUploadStart:function(e){var i=this.agent.getItem(e.id);if(i&&(i=i.node)&&i)BX.addClass(i,"mobile-grid-field-file-wait")},onUploadProgress:function(e,i){},onUploadDone:function(e,i){var t=this.agent.getItem(e.id);if(!t||!((t=t.node)&&t))return;BX.removeClass(t,"mobile-grid-field-file-wait");var l=i["file"];e.file={id:l["attachId"],name:l["name"]};var a=BX.findChildByClassName(t,"mobile-grid-field-file-name",true);if(a)a.innerHTML=l["name"];var o=BX.create("INPUT",{attrs:{type:"hidden",name:this.controlName,value:l["attachId"]}});t.appendChild(o);BX.onCustomEvent(this,"onChange",[this,o]);this.bindFile(e)},onUploadError:function(e){var i=this.agent.getItem(e.id);if(!i||!((i=i.node)&&i))return;BX.removeClass(i,"mobile-grid-field-file-wait");BX.addClass(i,"mobile-grid-field-file-error")},bindFile:function(e){var i=this.agent.getItem(e.id);if(!i||!((i=i.node)&&i))return;if(e.dialogName=="BX.UploaderImage"){if(!BX.hasClass(i,"mobile-grid-field-file-image"))BX.addClass(i,"mobile-grid-field-file-image");BX.removeClass(i,"mobile-grid-field-file-file")}var t=BX.findChild(i,{tagName:"DEL"},true);if(t&&!t.hasAttribute("bx-bound")){t.setAttribute("bx-bound","Y");BX.bind(t,"click",BX.delegate(function(){this.deleteFile(e)},this))}if(e.file&&e.file.id){var l=BX.findChildByClassName(i,"mobile-grid-field-file-name",true);if(l&&!l.hasAttribute("bx-bound")){l.setAttribute("bx-bound","Y");BX.bind(l,"click",BX.delegate(function(){this.openFile(e)},this))}}},deleteFile:function(e){var i=this.agent.getItem(e.id);if(i&&(i=i.node)&&i)BX.remove(i);BX.onCustomEvent(this,"onChange",[this,i])},openFile:function(e){var i=e.file.id,t=this.urls.getAttach.replace("#id#",e.file.id).replace("#name#",e.file.name);if(i.indexOf("n")===0){i=i.replace("n","");t=this.urls.getFile.replace("#id#",i).replace("#name#",e.file.name)}BXMobileApp.UI.Document.open({url:t})}};return i}();BX.Disk.UFMobileView=function(){var e=function(e){this.dialogName="DiskFileDialogView";this.params=e;this.CID=e["UID"];this.container=BX("diskuf-placeholder-"+e["UID"]);this.urls["getAttach"]=BX.message("SITE_DIR")+this.urls["getAttach"];this.urls["getFile"]=BX.message("SITE_DIR")+this.urls["getFile"];if(e["values"]&&e["values"].length>0)this.init(e["values"]);return this};e.prototype={urls:{getAttach:"mobile/ajax.php?mobile_action=disk_uf_view&action=download&ncc=1&attachedId=#id#&filename=#name#",getFile:"mobile/ajax.php?mobile_action=disk_download_file&action=downloadFile&fileId=#id#&filename=#name#"},init:function(e){for(var i=0;i<e.length;i++){this.bindNode(e[i])}},bindNode:function(e){if(BX(e)&&!e.hasAttribute("bx-bound")){BX.bind(BX(e),"click",BX.delegate(this.openFile,this));e.setAttribute("bx-bound","Y")}},openFile:function(){var e=BX.proxy_context;if(!BX(e))return;var i=e.getAttribute("id").replace("diskuf-",""),t=BX.findChild(e,{className:"mobile-grid-field-file-name"},true),l=t?t.innerHTML:"",a=this.urls.getAttach.replace("#id#",i).replace("#name#",l);if(i&&l){if(i.indexOf("n")===0){i=i.replace("n","");a=this.urls.getFile.replace("#id#",i).replace("#name#",l)}console.log("url:",a);BXMobileApp.UI.Document.open({url:a})}}};return e}();BX.Disk.UFMobile.add=function(e){e["values"]=BX.findChildren(BX("diskuf-placeholder-"+e["UID"]),{className:"mobile-grid-field-file-item"},false);i[e["UID"]]=new BX.Disk.UFMobile(e)};BX.Disk.UFMobile.addView=function(e){e["values"]=BX.findChildren(BX("diskuf-placeholder-"+e["UID"]),{className:"mobile-grid-field-file-item"},false);i[e["UID"]]=new BX.Disk.UFMobileView(e)};BX.Disk.UFMobile.getByName=function(e){for(var t in i){if(i.hasOwnProperty(t)){if(i[t]["controlName"]==e||i[t]["controlName"]==e+"[]"){return i[t]}}}return null}})(window);
//# sourceMappingURL=script.map.js